<?php
namespace app\admin\controller;

class Template extends Base
{
    public function __construct()
    {
        parent::__construct();
    }
    public function index()
    {
        $this->isLogin();
        $templateModel = D('Template');
        $list = $templateModel->getList();
        $this->assign('list', $list);
        return $this->fetch();
    }
    public function add()
    {
        $this->isLogin();
        return $this->fetch();
    }
    public function postAdd(){
        $typeId = I('post.type_id');
        $tempName = I('post.temp_name');
        if(empty($typeId)||empty($tempName))
			manage_log_error();
            return $this->error('删除失败', U('Template/add'));
        $templateModel = D('Template');
        $result = $templateModel->addTemp($typeId, $tempName);
        if(!empty($result)){
			manage_log_success();
            return $this->success('添加成功', U('Template/index'));
        }else{
			manage_log_error();
            return $this->error('添加失败', U('Template/add'));
        }
    }
    public function del()
    {
        $this->isLogin();
        $id = I('get.id');
        $templateModel = D('Template');
		
		 $reconfirm = $this->reconfirm('删除后无法恢复，是否确认删除？');
        if(!$reconfirm){
			 return $this->error('取消删除', U('Template/index'));
		}
		
        $result = $templateModel->deleteTemp($id);
        if(!empty($result)){
			manage_log_success();
            return $this->success('删除成功', U('Template/index'));
        }else{
			manage_log_error();
            return $this->error('删除失败', U('Template/index'));
        }
    }
}
